package com.example.demo.client;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo._config.ThirdProperties;
import com.example.demo.auth.JsonKit;
import com.example.demo.auth.Result;
import com.jfinal.qyweixin.sdk.api.ApiResult;

@Service
public class ThirdServerApi extends BaseServerApi {


	private final static Logger log = LoggerFactory.getLogger(ThirdServerApi.class);

	@Autowired
	ThirdProperties thirdProp;
	
	@Override
	protected String getApiHost() {
		return thirdProp.getApiHost();
	}

	@Override
	protected String getAppid() {
		return thirdProp.getAppid();
	}

	@Override
	protected String getAppsecret() {
		return thirdProp.getAppsecret();
	}

	@Override
	protected String getToken() {
		return getToken("/token");
	}

	public ApiResult getUserInfo(String userid) {
		
		log.info("=====================获取投诉用户信息========================");
		
		if ("".equals(userid) || userid == null) {
			return new ApiResult(Result.me().error("参数无效"));
		}
		
		Map<String, Object> params = new HashMap<String, Object>();
        params.put("userid", userid);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("data", params);

		log.info("=====================参数========================");
		log.info(JsonKit.general.toJson(params));
		log.info("=====================参数end========================");
		
		String url = packageSignUrlEncode("/api/user", getApiHost(),
				getAppid(), getToken("/token"));

		String jsonStr = HttpHttpsUtil.httpUrlDataPost(url, JsonKit.general.toJson(data));

		log.info(jsonStr);
		log.info("=====================end======================");
		return new ApiResult(jsonStr);
	}
	
}
